package cn.edu.sjtu.se.dslab.helper;

import java.net.MalformedURLException;
import java.net.URL;

import javax.servlet.ServletContext;

import org.apache.log4j.Logger;
import org.springframework.web.context.ServletContextAware;


/** 
 * @ClassName: ApplicationContextHelper
 * @Description:  Help to get the reference of the ServletContext
 * @author longshaohang
 * @date 2014-5-24 下午20:41:42
 * 
 */
public class ServletContextHelper implements ServletContextAware{
	
	public static final Logger logger = Logger.getLogger(ServletContextHelper.class);

	private static ServletContext servletContext;
	private static URL realPath;

	@Override
	public void setServletContext(ServletContext sc) {
		servletContext = sc;
		try {
			realPath = servletContext.getResource("/");
		} catch (MalformedURLException e) {
			logger.error(e.getStackTrace());
		}
		
	}
	
	public static String getRealPath(){
		return realPath.getPath();
	}
	
	public static ServletContext getServletContext(){
		return servletContext;
	}
}

